package kcg;

import static org.junit.Assert.assertTrue;
import kcg.test.RobotTestBed;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.events.BattleStartedEvent;
import robocode.control.snapshot.IRobotSnapshot;

/**
 * Illustrates JUnit testing of Robocode robots. This test simply verifies that MikeTerry stays 
 * out of the center.
 * 
 * @author Philip Johnson Modified for personal use by Kelvin Green
 */

public class TestMikeTerryStayOutCenter extends RobotTestBed {

  double height = 0;
  double width = 0;
  int turn = 0;
  boolean inCenter = true;

  @Override
  public String getRobotNames() {
    return "sample.Fire,kcg.MikeTerry";
  }

  /**
   * This test runs for five rounds.
   * 
   * @return The number of rounds in this test
   */
  @Override
  public int getNumRounds() {
    return 5;
  }

  /**
   * After each turn, check to see if MikeTerry will leave the outter wall radius.
   * 
   * @param event Information about the current state of the battle
   */

  @Override
  public void onTurnEnded(TurnEndedEvent event) {
    IRobotSnapshot robot = event.getTurnSnapshot().getRobots()[1];
    double x = robot.getX();
    double y = robot.getY();
    turn++;

    if (turn > 10) {
      if (x > (width - 40) || x < 40 || y > (height - 40) || y < 40) {
        inCenter = false;
      }
      else {
        inCenter = true;
      }
    }

  }

  /**
   * Asserts that MikeTerry does not leave the outter wall radius.
   * 
   * @param event Details about the started battle
   */
  @Override
  public void onBattleStarted(BattleStartedEvent event) {
    height = event.getBattleRules().getBattlefieldHeight();
    width = event.getBattleRules().getBattlefieldWidth();
  }

  /**
   * Asserts thatMikeTerry does not leave the outter wall radius.
   * 
   * @param event Details about the completed battle
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertTrue(!inCenter);
  }

}
